Skip to content

feat(#2369): Add webdev_colors_folder option #2375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 26, 2023

Conversation

antoniosarosi
Copy link
Contributor

Implements feature #2369

I started writing a little draft to provide an option that allows the user to change the icon and color of a directory based on its name. I added a new option webdev_colors_folder and I changed the get_folder_icon function as mentioned here. Now you can do this:

require("nvim-web-devicons").setup {
    strict = true,
    override_by_filename = {
        [".git"] = {
            icon = "",
            color = "#ff0000",
            name = "Gitignore"
        },
        [".github"] = {
            icon = "",
            color = "#ff0000",
            name = "Github"
        },
    }
}

require("nvim-tree").setup {
  renderer = {
    icons = {
      webdev_colors_folder = true,
    }
  }
}

And get this result:

Click to show screenshot

2023-08-15-000051_819x651_scrot

But I have some questions before continuing. nvim-web-devicons doesn't distinguish between directories and files, so if you create a file that matches one of the override_by_filename keys it will get the same icon and color, which maybe you intended only for directories, not files. I am not sure how to override only directory names.

On the other hand, what should happen with overriden icons when the directory is open VS closed? Should it use the same overriden icon for both cases, use the overriden icon only for closed directories while using glyphs.folder.open for open directories, or should it allow the user to customize both closed and open icons/colors? I think the last option is not possible with override_by_filename as nvim-web-devicons doesn't know whether a directory is closed or not, that is handled by nvim-tree.

Finally, I'm not sure if get_folder_icon should return both the icon and highlight or if there should be an equivalent to Builder:_get_highlight_override, I implemented it as simply as I could.

@alex-courtis
Copy link
Member

On the other hand, what should happen with overriden icons when the directory is open VS closed?

I'm happy to use the same one for open vs closed. The user can see the state via the arrows or indent markers.

Finally, I'm not sure if get_folder_icon should return both the icon and highlight or if there should be an equivalent to Builder:_get_highlight_override, I implemented it as simply as I could.

We can follow the file pattern i.e. create a get_folder_icon_webdev which should simplify things.

@alex-courtis
Copy link
Member

We do have an issue: folder icons will appear for users when they didn't previously. We need to preserve existing behaviour.

There are really two questions for files and folders:

  1. show webdev icon
  2. colourise webdev icon

For 1 we have no solution, which I think #2361 is about. The only way to prevent icons is to disable the plugin.

Proposal: add options:
0001-granular-web_devicons-config.patch.gz

We will need to add a silent refactor of renderer.icons.webdev_colors to renderer.icons.web_devicons.file.color in legacy.lua to not break existing users.

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for the contribution; this will resolve a larger problem.

@antoniosarosi
Copy link
Contributor Author

We do have an issue: folder icons will appear for users when they didn't previously. We need to preserve existing behaviour.

Isn't this controlled by the new webdev_colors_folder option? Since it's set to false by default, folder icons should behave the same as before unless the user sets the option to true , or am I misunderstanding?

@alex-courtis
Copy link
Member

Many thanks for the updates. I'll get to this on the weekend.

@alex-courtis
Copy link
Member

Isn't this controlled by the new webdev_colors_folder option? Since it's set to false by default, folder icons should behave the same as before unless the user sets the option to true , or am I misunderstanding?

I'm scope creeping here. We never had any mechanism for controlling the display of icons, just their colour.

We require both controls for folders to prevent breaking existing folder icon behaviour. We should add both controls for file icons now, as the configuration and behaviour would be very inconsistent between files and folders.

@antoniosarosi
Copy link
Contributor Author

I'm scope creeping here. We never had any mechanism for controlling the display of icons, just their colour.

Still not sure what you mean, if you use override_by_filename option when setting up nvim-web-devicons you can change the icon of any file. Then there's also webdev_colors in nvim-tree which is set to true by default. So you can control both icons and colors of files using a combination of override_by_filename and webdev_colors.

webdev_colors_folder does almost the same except you can't control icons and colors separately, is that the issue?

Maybe splitting it into two options like webdev_colors_folder and webdev_icons_folder would be better? That would allow the user to only change the icons or both icons and colors of directories.

@alex-courtis
Copy link
Member

alex-courtis commented Aug 21, 2023

Maybe splitting it into two options like webdev_colors_folder and webdev_icons_folder would be better? That would allow the user to only change the icons or both icons and colors of directories.

Yes please.

Please git apply 0001-granular-web_devicons-config.patch the patch linked above. I've drafted all those options in help.

Don't worry about the migration; I'll do that after you've finished the functionality.

@antoniosarosi
Copy link
Contributor Author

I applied the patch and implemented web_devicons.file and web_devicons.folder options. I tested all the combinations and it seems to work pretty well. Let me know if you find any bug.

@alex-courtis
Copy link
Member

That's fantastic! I'll get to this on the weekend.

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works beautifully:

file = { enable = false, color = false, }, folder = { enable = false, color = false, },
file = { enable = false, color = false, }, folder = { enable = false, color = true, },
file = { enable = false, color = false, }, folder = { enable = true, color = false, },
file = { enable = false, color = false, }, folder = { enable = true, color = true, },

file = { enable = false, color = true, }, folder = { enable = true, color = true, },
file = { enable = true, color = true, }, folder = { enable = true, color = true, },
file = { enable = true, color = false, }, folder = { enable = true, color = true, },

renderer.icons.webdev_colors -> renderer.icons.web_devicons.file.color

Many thanks for your contribution, you have gone well beyond the call of duty.

@alex-courtis alex-courtis merged commit b144b33 into nvim-tree:master Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants